package com.ruoyi.project.mahjong.controller;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.redis.RedisCache;
import com.ruoyi.project.system.domain.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.mahjong.domain.OtherPrice;
import com.ruoyi.project.mahjong.service.IOtherPriceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 其他消费Controller
 *
 * @author ruoyi
 * @date 2023-12-06
 */
@RestController
@RequestMapping("/mahjong/otherprice")
public class OtherPriceController extends BaseController
{
    @Autowired
    private IOtherPriceService otherPriceService;
    @Autowired
    private RedisCache redisCache;
    /**
     * 查询其他消费列表
     */
    @PreAuthorize("@ss.hasPermi('mahjong:otherprice:list')")
    @GetMapping("/list")
    public TableDataInfo list(OtherPrice otherPrice)
    {SysUser user = SecurityUtils.getLoginUser().getUser();
        Long shopId = redisCache.getCacheObject(Constants.SHOP_SUF + user.getUserId());
        otherPrice.setShopId(shopId);
        startPage();
        List<OtherPrice> list = otherPriceService.selectByOther(otherPrice);
        return getDataTable(list);
    }

    /**
     * 导出其他消费列表
     */
    @PreAuthorize("@ss.hasPermi('mahjong:otherprice:export')")
    @Log(title = "其他消费", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OtherPrice otherPrice)
    {
        List<OtherPrice> list = otherPriceService.selectOtherPriceList(otherPrice);
        ExcelUtil<OtherPrice> util = new ExcelUtil<OtherPrice>(OtherPrice.class);
        return util.exportExcel(list, "otherprice");
    }

    /**
     * 获取其他消费详细信息
     */
    @PreAuthorize("@ss.hasPermi('mahjong:otherprice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(otherPriceService.selectOtherPriceById(id));
    }

    /**
     * 新增其他消费
     */
    @PreAuthorize("@ss.hasPermi('mahjong:member:out')")
    @Log(title = "其他消费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OtherPrice otherPrice)
    { SysUser user = SecurityUtils.getLoginUser().getUser();
        Long shopId = redisCache.getCacheObject(Constants.SHOP_SUF + user.getUserId());

        otherPrice.setStaffId(user.getUserId());
        otherPrice.setShopId(shopId);
        return toAjax(otherPriceService.insertOtherPrice(otherPrice));
    }

    /**
     * 修改其他消费
     */
    @PreAuthorize("@ss.hasPermi('mahjong:otherprice:edit')")
    @Log(title = "其他消费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OtherPrice otherPrice)
    {
        return toAjax(otherPriceService.updateOtherPrice(otherPrice));
    }

    /**
     * 删除其他消费
     */
    @PreAuthorize("@ss.hasPermi('mahjong:otherprice:remove')")
    @Log(title = "其他消费", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(otherPriceService.deleteOtherPriceByIds(ids));
    }
}
